package org.yxing.palpalgps.models;

import java.util.Date;

import org.yxing.palpalgps.provider.RecentChatsProvider.RecentChats;
import org.yxing.palpalgps.utils.MyBase64;

public class ChatMessageModel {
    
    private long id;
    private String from;
    private String to;
    private String body;
    private String encodeBody;
    private String type;
    private Date date;
    
    public ChatMessageModel(long id) {
        setId(id);
    }
    
    public ChatMessageModel() {
        
    }
    
    public ChatMessageModel(String from, String to, String body) {
        setFrom(from);
        setTo(to);
        setBody(body);
        setDate(new Date());
    }
    
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public String getBody() {
        if (body == null && encodeBody != null)
            body = MyBase64.decode(encodeBody);
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
    
    public String toString() {
        return getFrom() + ", " + getTo() + ", " + getBody();
    }

    public String getEncodeBody() {
        if (encodeBody == null && body != null)
            encodeBody = MyBase64.encode(body);
        return encodeBody;
    }

    public void setEncodeBody(String encodeBody) {
        this.encodeBody = encodeBody;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = (type == RecentChats.TYPE_CHAT) ? RecentChats.TYPE_CHAT : RecentChats.TYPT_GROUP;
    }
}